package com.apop.accompanyH5.home.controller;

import cn.hutool.core.bean.BeanUtil;
import com.apop.accompanyH5.home.domain.entity.Hospital;
import com.apop.accompanyH5.home.service.HospitalService;
import com.apop.accompanyH5.home.domain.vo.HospitalSaveReqVO;
import com.apop.common.model.PageResult;
import com.apop.common.model.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * <p>
 *  Hospital前端控制器
 * </p>
 *
 * @author JiayiZheng
 * @since 2024-10-07
 */
@RestController
@RequestMapping("/pzh5/hospital")
public class HospitalController {

    @Resource
    private HospitalService hospitalService;

    /**
     * 医院信息单个查询
     * @param id
     * @return
     */
    @GetMapping("/info")
    public Result<Hospital> getHospitalById(@RequestParam Integer id) {
        return Result.success(hospitalService.getHospitalById(id));
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public Result getHospitalPage(
            @RequestParam(name = "pageNum")  Integer pageNum,
            @RequestParam(name = "pageSize") Integer pageSize) {
        PageResult page = hospitalService.getHospitalList(pageNum,pageSize);
        return Result.success(page);
    }

    /**
     * 新增医院
     * @param hospitalSaveReqVO
     * @return
     */
    @PostMapping("/create")
    public Result<Boolean> createHospital(@Valid @RequestBody HospitalSaveReqVO hospitalSaveReqVO) {
        Hospital hospitalDO = BeanUtil.toBean(hospitalSaveReqVO,Hospital.class);
        return Result.success(hospitalService.save(hospitalDO));
    }




}
